<?php include "../public/header.php"?>
<?php include "../public/header_public.php"?>
<body class="laytp-container">
<div style="height: 45px"></div>
<div id="opt_nav">
</div>
<div id="dialog">
    <div class="page-title" id="page-title">
        <div class="page-title-con">
            <span class="title">选择储备合同信息</span>
            <div class="move_title"></div>
            <div class="page-title-opt-list">
                <button class="layui-btn layui-btn-sm btn-dark marginr5" type="button" id="submit">确定</button>
                <span id="page-close" class="page-close" onclick="layer_close()">×</span>
            </div>
        </div>
    </div>
</div>
<div class="layui-card" id="search-form">
    <div class="layui-card-body">
        <form class="layui-form" id="TableSearchFormId" lay-filter="TableSearchForm" onkeydown="keyTableSearch('TableSearchForm', 'datalist')">
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-md3">
                        <label class="layui-form-label">销售方</label>
                        <div class="layui-input-block">
                            <input type="text" name="lianer" id="lianer" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">合同名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">合同编号</label>
                        <div class="layui-input-block">
                            <input type="text" name="number" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3  search_hide none">
                        <label class="layui-form-label">签订状态：</label>
                        <div class="layui-input-block">
                            <select id="state" name="state" lay-filter="state">
                                <option value="">请选择</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">采购类型</label>
                        <div class="layui-input-block">
                            <div id="caitype" class="xmselect_div">
                                <div class="xmselect_title">请选择</div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">合同类型：</label>
                        <div class="layui-input-block">
                            <select id="hetype" name="hetype" lay-filter="hetype">
                                <option value="">请选择</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">供应方(乙方)</label>
                        <div class="layui-input-block">
                            <input type="text" name="gonger" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">购买方(甲方)</label>
                        <div class="layui-input-block">
                            <div id="caier" class="xmselect_div">
                                <div class="xmselect_title">请选择</div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">签订日期</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="qiandt" placeholder="请输入" autocomplete="off" class="layui-input bdate_sea_range_ymd">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">审核状态：</label>
                        <div class="layui-input-block">
                            <select id="status" name="status" lay-filter="status">
                                <option value="">请选择</option>
                                <option value="1">流程（审批通过）</option>
                                <option value="0">流程（审批中）</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <div class="layui-form-item search-div">
                            <div class="layui-form-item layui-inline">
                                <input type="hidden" id="enginid" name="enginid">
                                <button class="laytp-btn laytp-btn-md laytp-btn-primary" id="TableSearchButton" type="button"><i class="layui-icon layui-icon-search"></i>查询</button>
                                <button class="layui-btn layui-btn-primary" onclick="listTableReset()" id="TableSearchReset" type="reset" ><i class="layui-icon layui-icon-refresh"></i>重置</button>
                                <div id="search_open" onclick="toggle_search()">
                                    <i class="layui-icon layui-icon-down"></i>展开
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="layui-card" id="table-card">
    <div class="layui-card-body">
        <div class="layui-row">
            <div class="layui-col-md12" id="table_list">
                <div class="layui-card-body">
                    <table id="datalist" lay-filter="datalist"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    // 单选多选分类 默认单选 choose_type传值为多选
    var choose_type = getQueryVariable('choose_type');
    if(choose_type === undefined || choose_type === false){
        choose_type = 'radio';
    }else{
        choose_type = 'checkbox';
    }

    var parent_dom = getQueryVariable('dom');
    var parent_domkey = getQueryVariable('domkey');
    var parent_page = getQueryVariable('page');
    var parent_gonger = getQueryVariable('gonger') || '';
    parent_gonger = decodeURI(parent_gonger);
    if(parent_gonger){
        $("#gongerdiv").hide();
    }



    var parent_caihetype = getQueryVariable('caihetype') || 0;
    if(parent_caihetype > 0){
        $("#caihetype").prop('disabled',true);
    }

    var parent_lianer = decodeURI(getQueryVariable('lianer') || '') || '';
    if(parent_lianer){
        $("#lianer").val(parent_lianer);
        $("#lianer").prop('disabled', true);
        $("#lianer").addClass('disabled');
    }


    layui.use(["laytp",'laypage','table','dropdown','form','soulTable'], function () {
        var laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, form = layui.form, soulTable = layui.soulTable;

        $('#TableSearchReset').click(function () {
            $('.xmselect_div>xm-select').find('.xm-label-block').css('display','none');
            $('.xmselect_div').append('<div class="xmselect_title">请选择</div>');
            searchTableFunc(form, table)
        });

        $("#cols_table").hide();
        $("#export_table").hide();
        table.render({
            elem: "#datalist",id: "datalist"
            ,url: facade.url(ask_opt_get_contract_chu),where: {caihetype:parent_caihetype,gonger:parent_gonger,lianer_zhi:parent_lianer}, page: true
            , height: 'full-140'
            ,soulSort: TabInit.soulSort,method: TabInit.method, toolbar: TabInit.toolbar, overflow: TabInit.overflow
            ,defaultToolbar: ['', '', ''],filter: TabInit.filter
            ,request: TabInit.request,response: TabInit.response,contextmenu:get_table_contextmenu(soulTable)
            ,parseData: function(res){

                var state_str = '<option value="">请选择</option>';
                var state = res.data.state;
                for (var key in state){
                    if(res.data.is_state == key){
                        state_str += '<option value="'+key+'" selected>'+state[key]+'</option>';
                    }else {
                        state_str += '<option value="'+key+'">'+state[key]+'</option>';
                    }

                }
                $("#state").html(state_str);


                var hetype_str = '<option value="">请选择</option>';
                var hetype = res.data.hetype;
                for (var key in hetype){
                    if(res.data.is_hetype == key){
                        hetype_str += '<option value="'+key+'" selected>'+hetype[key]+'</option>';
                    }else {
                        hetype_str += '<option value="'+key+'">'+hetype[key]+'</option>';
                    }

                }
                $("#hetype").html(hetype_str);

                xmselect_dan('caitype', res.data.caitype, res.data.is_caitype, function (res) {
                    setTimeout(function () {
                        searchTableFunc(form, table);
                    },100)
                })


                xmselect_dan('caier', res.data.caier, res.data.is_caier, function (res) {
                    setTimeout(function () {
                        searchTableFunc(form, table);
                    },100)
                })
                render_from();
                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.data.total,
                    "data": res.data.data.data
                };
            }
            ,cols: [[
                {type:choose_type,fixed:'left'}
                ,{field: 'state_name', title: '合同状态'}
                ,{field: 'lianer', title: '销售方'}
                ,{field: 'name', title: '合同名称'}
                ,{field: 'number', title: '合同编号'}
                ,{field: 'caitype_name', title: '采购类型'}
                ,{field: 'hetype_name', title: '合同类型'}
                ,{field: 'qianpiaotype_name', title: '发票类型'}
                ,{field: 'gonger', title: '供应方(乙方)'}
                // ,{field: 'gongtel', title: '乙方联系电话'}
                ,{field: 'caier_name', title: ' 购买方(甲方)'}
                ,{field: 'myer', title: '签订人'}
                ,{field: 'qiandt', title: '签订日期'}
                ,{field: 'money', title: '合同金额(元)',totalRow: true}
                ,{field: 'rate', title: '税率(%)'}
            ]]
            ,done : function(res, curr, count){
                $(".layui-table-tool").remove()
                soulTable.render(this);
            }
        });
        listTableSearch(form, table);


        $('#submit').on('click', function () {
            var checkStatus = layui.table.checkStatus('datalist');
            var data = checkStatus.data;
            if(data.length < 1){
                facade.error("请选择数据");return false;
            }

            if(parent_page == 'payment_engin'){
                var pub_qutype = parent.pub_qutype;
                var nums = $("#list_list tr", parent.document).length;
                for (var key in data){
                    var str = '';
                    nums++;
                    str += '<tr>';
                    str += '<td style="width: 45px">'+nums+'</td>';
                    str += '<td><input type="text" class="layui-input " readonly value="储备合同付款"></td>';
                    str += '<td>';
                    str += '<input type="text" futype="2" caiid="'+data[key].id+'" readonly value="'+data[key].name+'('+data[key].number+')'+'" class="layui-input name disabled">';
                    str += '</td>';
                    str += '<td><input type="text" value="'+data[key].gonger+'" readonly class="layui-input gonger disabled"></td>';
                    str += '<td><input type="text" class="layui-input leiyifu" value="'+data[key].leiyifu+'"></td>';
                    str += '<td><input type="text" class="layui-input leiyipiao" value="'+data[key].leiyipiao+'"></td>';
                    str += '<td><input type="text" class="layui-input leiyiqian" value="'+data[key].leiyiqian+'"></td>';
                    str += '<td><input type="number" class="layui-input money"></td>';


                    str += '<td>';
                    str += '<select class="layui-select qutype">';
                    str += '<option value="">请选择</option>';
                    for (var mmm in pub_qutype){
                        str += '<option value="'+mmm+'">'+pub_qutype[mmm]+'</option>';
                    }
                    str += '</select>';
                    str += '</td>';

                    str += '<td><div class="incdaotype incdaotype'+nums+'" key="'+nums+'"></div></td>';

                    str += '<td><input type="text" class="layui-input banknum" value="'+data[key].banknum+'"></td>';
                    str += '<td><input type="text" class="layui-input bankname" value="'+data[key].bankname+'"></td>';
                    str += '<td><input type="text" class="layui-input explain"></td>';
                    str += '</tr>';
                    $("#list_list", parent.document).append(str);
                    parent.xmselect_list_dan('incdaotype'+nums, parent.pub_incdaotype, '');
                }


                if (typeof(window.parent.update_refresh_row_func)!="undefined"){
                    window.parent.update_refresh_row_func();
                }
            }else if(parent_page == 'hou_chushui'){
                var nums = $("#list_list tr", parent.document).length;
                for (var key in data){
                    var str = '';
                    nums++;
                    str += '<tr>';
                    str += '<td style="width: 45px">'+nums+'</td>';
                    str += '<td><input type="text" chuid="'+data[key].id+'" value="'+data[key].name+'" class="layui-input chuid disabled" readonly></td>';
                    str += '<td><input type="text"  value="'+data[key].gonger+'" readonly class="layui-input xiaoer disabled"></td>';
                    str += '<td><input type="text" value="'+data[key].lei_kuan+'" class="layui-input disabled lei_kuan" disabled></td>';
                    str += '<td><input type="text" value="'+data[key].lei_piao+'" class="layui-input disabled lei_piao" disabled></td>';
                    str += '<td><input type="text" value="'+data[key].lei_shui+'" class="layui-input disabled lei_shui" disabled></td>';
                    str += '<td>';
                    str += '<select class="layui-select yiju">';
                    str += '<option value="">请选择</option>';
                    for (var mmm in parent.pub_yiju){
                        str += '<option value="'+mmm+'">'+parent.pub_yiju[mmm]+'</option>';
                    }
                    str += '</select>';
                    str += '</td>';
                    str += '<td><input type="number" class="layui-input yijurate"></td>';
                    str += '<td><input type="number" class="layui-input money"></td>';
                    str += '<td><div class="incdaotype incdaotype'+nums+'" key="'+nums+'"></div></td>';
                    var ListZhangName = '';
                    var ListZhangKai = '';
                    var ListZhangNum = '';
                    if(data[key].dealcomlist){
                        ListZhangName = data[key].dealcomlist.zhangname
                        ListZhangNum = data[key].dealcomlist.banknum
                        ListZhangKai = data[key].dealcomlist.bankname
                    }
                    str += '<td><input type="text" onclick="choose_dealcom_bank(this)" value="'+ListZhangName+'" readonly class="layui-input bankzhang disabled"></td>';
                    str += '<td><input type="text" value="'+ListZhangNum+'" disabled class="layui-input banknum disabled"></td>';
                    str += '<td><input type="text" value="'+ListZhangKai+'" disabled class="layui-input bankname disabled"></td>';
                    str += '<td><input type="text" class="layui-input explain"></td>';
                    str += '</tr>';
                    $("#list_list", parent.document).append(str);
                    parent.xmselect_list_dan('incdaotype'+nums, parent.pub_incdaotype, '');
                }

                if (typeof(window.parent.update_refresh_row_func)!="undefined"){
                    window.parent.update_refresh_row_func();
                }
            }else if(parent_page == 'hou_chujin'){
                var nums = $("#list_list tr", parent.document).length;
                for (var key in data){
                    var str = '';
                    nums++;
                    str += '<tr>';
                    str += '<td style="width: 45px">'+nums+'</td>';
                    str += '<td><input type="text" chuid="'+data[key].id+'" value="'+data[key].name+'" class="layui-input chuid disabled" readonly></td>';
                    str += '<td><input type="text"  value="'+data[key].gonger+'" readonly class="layui-input fuer disabled"></td>';
                    str += '<td><input type="text" value="'+data[key].lei_kuan+'" class="layui-input disabled lei_kuan" disabled></td>';
                    str += '<td><input type="text" value="'+data[key].lei_piao+'" class="layui-input disabled lei_piao" disabled></td>';
                    str += '<td><input type="text" value="'+data[key].lei_chumoney+'" class="layui-input disabled lei_chumoney" disabled></td>';
                    str += '<td><input type="number" class="layui-input money"></td>';
                    str += '<td><div class="incdaotype incdaotype'+nums+'" key="'+nums+'"></div></td>';
                    var ListZhangName = '';
                    var ListZhangKai = '';
                    var ListZhangNum = '';
                    if(data[key].dealcomlist){
                        ListZhangName = data[key].dealcomlist.zhangname
                        ListZhangNum = data[key].dealcomlist.banknum
                        ListZhangKai = data[key].dealcomlist.bankname
                    }
                    str += '<td><input type="text" onclick="choose_dealcom_bank(this)" value="'+ListZhangName+'" readonly class="layui-input bankzhang disabled"></td>';
                    str += '<td><input type="text" value="'+ListZhangNum+'" disabled class="layui-input banknum disabled"></td>';
                    str += '<td><input type="text" value="'+ListZhangKai+'" disabled class="layui-input bankname disabled"></td>';
                    str += '<td><input type="text" class="layui-input explain"></td>';
                    str += '<td><input type="text" onclick="choose_piao_chu_guan(this)" readonly class="layui-input difee disabled"><span class="difeeobj layui-hide"></span></td>';
                    str += '</tr>';
                    $("#list_list", parent.document).append(str);
                    parent.xmselect_list_dan('incdaotype'+nums, parent.pub_incdaotype, '');
                }

                if (typeof(window.parent.update_refresh_row_func)!="undefined"){
                    window.parent.update_refresh_row_func();
                }
            }else if(parent_page == 'piao_shou'){
                $("#list_list tr", parent.document).eq(parent_domkey).find('.caiid').val(data[0].name).attr('caiid',data[0].id);
                $("#list_list tr", parent.document).eq(parent_domkey).find('.gonger').val(data[0].gonger);
                if (typeof(window.parent.update_refresh_row_func)!="undefined"){
                    window.parent.update_refresh_row_func();
                }
            }else if(parent_page == 'piao_chu_one'){
                $("#list_list tr", parent.document).eq(parent_domkey).find('.chuid').val(data[0].name).attr('chuid',data[0].id);
                $("#list_list tr", parent.document).eq(parent_domkey).find('.xiaoer').val(data[0].gonger);
                if (typeof(window.parent.update_refresh_row_func)!="undefined"){
                    window.parent.update_refresh_row_func();
                }
            }else{
                var str = '<button type="button" class="layui-btn layui-btn-sm btn-dark" key="'+data[0].id+'"><span class="choose_content">'+data[0].name+'' +
                    '</span><span class="choose_close" onclick="choose_close(this, \''+parent_dom+'\')">×</span></button>';
                $("#"+parent_dom , parent.document).html(str);
                parent.formValid(parent_dom);

                if(parent_page == 'stuff_ru'){
                    var str2 = '<button type="button" class="layui-btn layui-btn-sm btn-dark" key="'+data[0].gonger+'"><span class="choose_content">'+data[0].gonger+'' +
                        '</span><span class="choose_close" onclick="choose_close(this, \''+parent_dom+'\')">×</span></button>';
                    $("#gonger" , parent.document).html(str2);
                    $("#gonger2" , parent.document).val(data[0].gonger);
                    $("#ru_list", parent.document).html('');
                }
                if(parent_page == 'stuff_cai'){
                    var str2 = '<button type="button" class="layui-btn layui-btn-sm btn-dark" key="'+data[0].gonger+'"><span class="choose_content">'+data[0].gonger+'' +
                        '</span><span class="choose_close" onclick="choose_close(this, \''+parent_dom+'\')">×</span></button>';
                    $("#gonger" , parent.document).html(str2);
                    $("#gonger2" , parent.document).val(data[0].gonger);
                    $("#cai_list", parent.document).html('');
                }
                if(parent_page == 'stuff_jie'){
                    $("#jie_list", parent.document).html('');
                }

                if(parent_page == 'subbao_shen'){
                    $("#gonger" , parent.document).val(data[0].gonger);
                    $("#list_list", parent.document).html('');
                }

                if(parent_page == 'labour_shen'){
                    $("#gonger" , parent.document).val(data[0].gonger);
                    $("#list_list", parent.document).html('');
                }

                if(parent_page == 'labour_hua'){
                    $("#cainumber" , parent.document).val(data[0].number);
                    $("#gonger" , parent.document).val(data[0].gonger);
                    $("#gonguser" , parent.document).val(data[0].gonguser+data[0].gongtel);
                }

                if(parent_page == 'device_jin'){
                    $("#gonger" , parent.document).val(data[0].gonger);
                    $("#list_list", parent.document).html('');
                }

                if(parent_page == 'device_jie'){
                    $("#gonger" , parent.document).val(data[0].gonger);
                    $("#list_list", parent.document).html('');
                }

                if(parent_page == 'contract_bian'){
                    $("#yuanfee" , parent.document).val(data[0].money);
                    $("#list_list", parent.document).html('');
                }

                if(parent_page == 'contract_cai_jie'){
                    $("#cai_money" , parent.document).val(data[0].money);
                    $("#cai_gonger" , parent.document).val(data[0].gonger);
                }

                if(parent_page == 'piao_chu'){
                    $("#heleijinfee" , parent.document).val(data[0].heleijinfee);
                    $("#leiyifu" , parent.document).val(data[0].leiyifu);
                    $("#heleijiefee" , parent.document).val(data[0].heleijiefee);
                }

                if(parent_page == 'contract_chu_jie'){
                    // $("#chu_money" , parent.document).val(data[0].money);
                    // $("#chu_gonger" , parent.document).val(data[0].gonger);
                    // $("#leiyifu" , parent.document).val(data[0].leiyifu);
                    // $("#heleijinfee" , parent.document).val(data[0].heleijinfee);
                    // $("#heleijiefee" , parent.document).val(data[0].heleijiefee);
                }

                if(parent_page == 'payment_chu'){
                    $("#chumoney" , parent.document).val(data[0].money);
                }

            }

            layer_close();
        });

    });
</script>
</body>
</html>
